package base;

import java.util.Random;
import java.util.Scanner;

public class lottery {
    public static void main(String[] args) {
        int[] arr = contains(); //计算机录入
        int[] userInputArr = userInputNumber(); //user录入
        //计算中将球数
        int redCount = 0, blueCount = 0; //
        //redBall:
        for (int i = 0; i < userInputArr.length - 1; i++) {
            for (int j = 0; j < arr.length - 1; j++) {
                if (userInputArr[i] == arr[j]){
                    redCount++;
                    break;
                }
            }
        }
        //blueBall:
        if (userInputArr[userInputArr.length - 1] == arr[arr.length - 1]) {
            blueCount++;
        }
        //判断中将情况
        if (redCount==6 && blueCount==1){
            System.out.println("恭喜您！中奖1000萬");
        }else if (redCount==6 && blueCount==0){
            System.out.println("恭喜您！中奖500萬");
        }else if (redCount == 5 && blueCount==1) {
            System.out.println("恭喜您！中奖3000元");
        } else if ((redCount==5 && blueCount==0)|| (redCount==4 && blueCount==1)) {
            System.out.println("恭喜您！中奖200元");
        } else if ((redCount==4 && blueCount==0)||(redCount==3 && blueCount==1)) {
            System.out.println("恭喜您！中奖10元");
        }else if ((redCount==2 && blueCount==1)||(redCount==1 && blueCount==1)||(redCount==0 && blueCount==1)){
            System.out.println("恭喜您！中奖5元");
        }else {
            System.out.println("恭喜您！没有中如何奖。。");
        }
    }

    //用户录入双色球的6红球和1蓝球 的号码：
    public static int[] userInputNumber(){
        int[] arr = new int[7];
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < 6;) {
            System.out.println("录入第"+(i+1)+"红球号码：");
            int redNumber = sc.nextInt();
            if (redNumber>=1 && redNumber<=33){
                if (!flag(arr,redNumber)){
                    arr[i] = redNumber;
                    i++;
                }else {
                    System.out.println("红球号码已重复！");
                }
            }else {
                System.out.println("错误！,红球号码超出范围！");
            }
        }
        while (true) {
            System.out.println("录入蓝球号码：");
            int blueNumber = sc.nextInt();
            if (blueNumber>=1 && blueNumber<=16){
                arr[arr.length-1] = blueNumber;
                break;
            }else {
                System.out.println("错误！,蓝球号码超出范围！");
            }
        }return arr;
    }
    //计算机选出 6个红球(不重复)，1个蓝球；
    public static int[] contains(){
        int[] arr = new int[7];
        Random r = new Random();
        for (int i = 0; i < 6; ) {
            int num = r.nextInt(33)+1;
            if ( !flag(arr,num)){
                arr[i] = num;
                i++;
            }
        }
        int num1 = r.nextInt(16)+1;
        arr[arr.length-1] = num1;
        return arr;
    }
    //判断数组是否存在重复的红球：存在返回true,否返回false;
    public static boolean flag(int[] arr,int num){
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == num){
                return true;
            }//是否重复
        }return false;
    }
}
